import http from '../../utils/http.js'

export function initCode(code) {
	return new Promise((resolve, reject) => {
		var params = {
			url: '/v1/app/authorized/wx_xcx_init',
			method: 'GET',
			data: {
				'js_code': code
			},
			callBack: (res) => {
				if (res.code == 0) {
					resolve(res)
				} else {
					reject(res.msg)
				}
			}
		}
		http.request(params)
	})
}

export function aliInitCode(code){
	return new Promise((resolve, reject) => {
		var params = {
			url: '/v1/app/authorized/alipay_xcx_init',
			method: 'GET',
			data: {
				'js_code': code
			},
			callBack: (res) => {
				if (res.code == 0) {
					resolve(res)
				} else {
					reject(res.msg)
				}
			}
		}
		http.request(params)
	})
}

export function getPhoneNumber(val) {
	return new Promise((resolve, reject) => {
		var params = {
			url: '/v1/app/member/mobile/login',
			method: 'POST',
			data: {
				generalEncryptedData:val.detail.encryptedData,
				iv:val.detail.iv
			},
			callBack: (res) => {
				if (res.code == 0) {
					resolve(res)
				} else {
					reject(res.msg)
				}
			}
		}
		http.request(params)
	})
}

export function getAliPhoneNumber(val){
	return new Promise((resolve, reject) => {
		var params = {
			url: '/v1/app/member/alipay/onekey/login',
			method: 'POST',
			data: {
				generalEncryptedData:val
			},
			callBack: (res) => {
				if (res.code == 0) {
					resolve(res)
				} else {
					reject(res.msg)
				}
			}
		}
		http.request(params)
	})
} 